<template>
  <div id="app" class="app-headers">
    <!--头部  -->
    <mt-header fixed title="首页">
      <span slot="left" @click="goback()" v-show="flag">
        <mt-button icon="back">返回</mt-button>
      </span>
      <mt-button icon="more" slot="right"></mt-button>
    </mt-header>
    <!-- 中部内容 -->
    <transition>
      <router-view/>
    </transition>

    <!--  -->
    <!--  -->
    <!-- 底部内容 -->
    <nav class="mui-bar mui-bar-tab">
      <!-- 底部tab -->
      <router-link id="defaultTab" class="mui-tab-item2" to="/home">
        <span class="mui-icon mui-icon-home"></span>
        <span class="mui-tab-label">首页</span>
      </router-link>
      <router-link class="mui-tab-item2" to="/vip">
        <span class="mui-icon mui-icon-extra mui-icon-extra-gold"></span>
        <span class="mui-tab-label">会员</span>
      </router-link>
      <router-link class="mui-tab-item2" to="/shopcart">
        <span class="mui-icon mui-icon-extra mui-icon-extra-cart">
          <span class="mui-badge" id="ball_car">{{$store.getters.getallcount}}</span>
        </span>
        <span class="mui-tab-label">购物车</span>
      </router-link>
      <router-link class="mui-tab-item2" to="/searchs">
        <span class="mui-icon mui-icon-search"></span>
        <span class="mui-tab-label">搜索</span>
      </router-link>
    </nav>

    <!-- --------------------------------------------- -->
  </div>
</template>

<script>
import "./mui/css/mui.css"; //引入自己下载的mui包
import home from "./components/home"; //引入子组件

export default {
  data() {
    return {
      show: false,
      flag: false
    };
  },
  watch: {
    $route: {
      //函数名字不可以改变    百度搜索的不知道原因替换会出错
      //监听路由
      handler: function(val, oldVal) {
        // console.log(val);
        var routers = [];
        routers = val;
        // console.log(routers.name);
        if (routers.name === "home") {
          this.flag = false;
          return true;
        } else {
          this.flag = true;
        }
      },
      // 深度观察监听
      deep: true
    }
  },
  components: {
    home
  },
  methods: {
    goback() {
      this.$router.go(-1); //点击返回按钮 只返回上一级
    }
  },
  mounted() {
    //解决tab 因为mui.js不能不能正常跳转    这种方法解决会让路由变成a标签式跳转
    // this.mui("body").on("tap", "a", function() {
    //   document.location.href = this.href;
    // });
  }
};
</script>
<style scope>
/* 因为头部是绝对定位 内容会被遮盖 */
.app-headers {
  padding-top: 40px;
  padding-bottom: 50px;
  overflow-x: hidden;
}
/* 切换动画 */
.v-enter {
  opacity: 0;
  transform: translateX(100%);
}
.v-leave-to {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.v-enter-active,
.v-leave-active {
  transition: 0.4s all ease;
}
/* 解决滑动报错 */
/* * {
  touch-action: pan-y;
} */

/* 修改tab不能跳转bug第二种  修改类 */
.mui-bar-tab .mui-tab-item2.mui-active {
  color: #007aff;
}
.mui-bar-tab .mui-tab-item2 {
  display: table-cell;
  overflow: hidden;
  width: 1%;
  height: 50px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #929292;
}
.mui-bar-tab .mui-tab-item2 .mui-icon {
  top: 3px;
  width: 24px;
  height: 24px;
  padding-top: 0;
  padding-bottom: 0;
}
.mui-bar-tab .mui-tab-item2 .mui-icon ~ .mui-tab-label {
  font-size: 11px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mint-header.is-fixed {
  z-index: 2;
}
</style>
